<template>
	<div>
		<el-dialog :title="$t('action.update')" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
			<el-tabs v-model="activeName">
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.basic')" :name="$t('tabpage.basic')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_name')" prop="name">
							<el-input v-model="form.name" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_name')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_stamp')" prop="stamp">
							<el-input v-model="form.stamp" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_stamp')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_stamp_cost')" prop="stamp_cost">
							<el-input v-model="form.stamp_cost" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_stamp_cost')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_change')" prop="change">
							<el-input v-model="form.change" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_change')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_change_cost')" prop="change_cost">
							<el-input v-model="form.change_cost" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_change_cost')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_sell')" prop="sell">
							<el-input v-model="form.sell" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_sell')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_buy')" prop="buy">
							<el-input v-model="form.buy" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_buy')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_commission_cost')" prop="commission_cost">
							<el-input v-model="form.commission_cost" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_commission_cost')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_quota')" prop="quota">
							<el-input v-model="form.quota" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_quota')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_plus_fee')" prop="plus_fee">
							<el-input v-model="form.plus_fee" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_plus_fee')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_with_min')" prop="with_min">
							<el-input v-model="form.with_min" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_with_min')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_with_max')" prop="with_max">
							<el-input v-model="form.with_max" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_with_max')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_with_fee')" prop="with_fee">
							<el-input v-model="form.with_fee" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_with_fee')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_with_fee_min')" prop="with_fee_min">
							<el-input v-model="form.with_fee_min" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_with_fee_min')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_recharge_fee')" prop="recharge_fee">
							<el-input v-model="form.recharge_fee" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_recharge_fee')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_recharge_fee_min')" prop="recharge_fee_min">
							<el-input v-model="form.recharge_fee_min" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_recharge_fee_min')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_min_capital')" prop="min_capital">
							<el-input v-model="form.min_capital" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_min_capital')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_min_bond')" prop="min_bond">
							<el-input v-model="form.min_bond" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_min_bond')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_extra_fee1')" prop="extra_fee1">
							<el-input v-model="form.extra_fee1" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_extra_fee1')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_extra_fee2')" prop="extra_fee2">
							<el-input v-model="form.extra_fee2" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_extra_fee2')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_extra_fee3')" prop="extra_fee3">
							<el-input v-model="form.extra_fee3" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_extra_fee3')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_manage_fee_cupon_ratio')" prop="manage_fee_cupon_ratio">
							<el-input v-model="form.manage_fee_cupon_ratio" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_manage_fee_cupon_ratio')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_profit_divide_ratio')" prop="profit_divide_ratio">
							<el-input v-model="form.profit_divide_ratio" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_profit_divide_ratio')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_capital_interest_day_per')" prop="capital_interest_day_per">
							<el-input v-model="form.capital_interest_day_per" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_capital_interest_day_per')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_capital_interest_week_per')" prop="capital_interest_week_per">
							<el-input v-model="form.capital_interest_week_per" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_capital_interest_week_per')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_capital_interest_month_per')" prop="capital_interest_month_per">
							<el-input v-model="form.capital_interest_month_per" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_capital_interest_month_per')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_capital_interest_free_per')" prop="capital_interest_free_per">
							<el-input v-model="form.capital_interest_free_per" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_capital_interest_free_per')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_capital_interest_vip_per')" prop="capital_interest_vip_per">
							<el-input v-model="form.capital_interest_vip_per" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_capital_interest_vip_per')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.extend')" :name="$t('tabpage.extend')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_popup_status')" prop="popup_status">
							<el-radio-group v-model="form.popup_status">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="0">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				 </el-row>  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_popup_content_1')" prop="popup_content_1">
							<TinymceEditor v-if="show" tinymceId="popup_content_1"  :tinymceContent.sync="form.popup_content_1"></TinymceEditor>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_popup_content_2')" prop="popup_content_2">
							<el-input  type="textarea" autoComplete="off" v-model="form.popup_content_2"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.CoreSet_popup_content_2')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				<el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CoreSet_other_parameters')" prop="other_parameters">
							<draggable v-model="form.other_parameters" v-bind="{group:'item'}" handle=".other_parameters-handle">
							<el-row v-for="(item,i) in form.other_parameters" :key="i">
								<el-col :span="9">
							    <el-form-item class="activeItem">
									<el-input  v-model="item.name" placeholder="参数名"/>
								</el-form-item>
								</el-col>
								<el-col :span="9">
							    <el-form-item class="activeItem">
									<el-input style="position:relative;left:5px;" v-model="item.value" placeholder="参数值"/>
								</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-button type="danger" size="mini" style="position:relative;left:15px"  icon="el-icon-close" @click="deleteItem('other_parameters',i)"></el-button>
									<el-button class="other_parameters-handle" type="success" size="mini" style="position:relative;left:15px" icon="el-icon-rank"></el-button>
								</el-col>
							</el-row>
							</draggable>
							<div>
								<el-button type="info" icon="el-icon-plus" style="padding:5px 7px" size="mini" @click="addItem('other_parameters')">{{$t('action.add')}}</el-button>
								<el-button v-if="form.other_parameters.length > 0" type="warning" icon="el-icon-delete" style="padding:5px 7px" size="mini" @click="clearItem('other_parameters')">{{$t('action.clear')}}</el-button>
							</div>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			</el-tabs>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">{{$t('system.confirm')}}</span>
					<span v-else>{{$t('system.submitting')}}</span>
				</el-button>
				<el-button :size="size" @click="closeForm">{{$t('system.cancel')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { update } from '@/api/app/coreset'
import draggable from "vuedraggable"
import TinymceEditor from '@/components/editor/TinymceEditor.vue'

export default {
	name:'coreSetupdate',
	components: {
	   		draggable,
	   		TinymceEditor,
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
		    dialog:{
			},
			form: {
			   name:'',
			   stamp:'',
			   stamp_cost:'',
			   change:'',
			   change_cost:'',
			   sell:'',
			   buy:'',
			   commission_cost:'',
			   quota:'',
			   plus_fee:'',
			   with_min:'',
			   with_max:'',
			   with_fee:'',
			   with_fee_min:'',
			   recharge_fee:'',
			   recharge_fee_min:'',
			   min_capital:'',
			   min_bond:'',
			   extra_fee1:'',
			   extra_fee2:'',
			   extra_fee3:'',
			   manage_fee_cupon_ratio:'',
			   profit_divide_ratio:'',
			   capital_interest_day_per:'',
			   capital_interest_week_per:'',
			   capital_interest_month_per:'',
			   capital_interest_free_per:'',
			   capital_interest_vip_per:'',
			   status:1,
			   popup_content_1:'',
			   popup_content_2:'',
			   popup_status:1,
			   other_parameters:[],
			   create_time:'',
			   update_time:'',
			},
		    initial:{},        
			loading:false,
			activeName:this.$t('tabpage.basic'),
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
			}
		}
	},
	methods: {
		open(){
			this.form = this.info
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					update(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		addItem(key){
			this.form[key].push({})
		},
		deleteItem(key,index){
			this.form[key].splice(index,1)
		},
		clearItem(key){
			this.form[key] = []
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss';
</style>
